<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>留言板 - {$site_name}</title>
    <meta name="keywords" content="{$site_seo_keywords}"/>
    <meta name="description" content="{$site_seo_description}"/>
    <meta name="viewport" content="width=device-width"/>


</head>
<body>
<div class="g-doc">


    <div class="g-bd">
        <div class="c-block block f-fl">
            <!-- <h1 class="bl4">{$term.name}</h1> -->
            <ol class="c-list">
                <li <if condition="$location == 'guestbookInfo'">class="active"</if> ><a href="/guestbook_info.html">查看留言</a></li>
                <li <if condition="$location == 'guestbook'">class="active"</if> ><a href="/guestbook.html">添加留言</a></li>
            </ol>
        </div>

        <div class="a-block f-fr">
            <div class="">
                <h5 class="mbx"><a href="/">首页</a>&nbsp;&nbsp; &gt; &nbsp;&nbsp;留言板</h5>
                <div class="guestbook">
                    <form action="" method="post" id="gb_form">
                        <div class="item">
                            <label for="">姓名：</label>
                            <input type="text" name="name" class="input"> *
                        </div>
                        <div class="item">
                            <label for="">邮箱：</label>
                            <input type="text" name="email" class="input">
                        </div>
                        <div class="item">
                            <label for="">联系电话：</label> 
                            <input type="text" name="phone" class="input">
                        </div>
                        <div class="item">
                            <label for="">QQ：</label> 
                            <input type="text" name="qq" class="input">
                        </div>
                        <div class="item">
                            <label for="" class="label_for_textarea">留言内容：</label>&nbsp;<textarea name="content" id="" cols="50" rows="4"></textarea>
                        </div>
                        <div class="clear"></div>
                        <div class="item">
                            <label for="">验证码：</label>
                            <input type="text" name="code" class="input" style="width: 80px;">
                            <img id="code_img" align="absmiddle" onclick="this.src=this.src+'?'" style="cursor:pointer;margin-left:0px;text-transform:uppercase;" alt="看不清？点击更换" src="/verify/4_14_100_40_guestbook">
                        </div>
                        <div class="item"><label for=""></label><input type="submit" value="提交" class="btn"></div>
                    </form>
                </div>
            </div>
        </div>
        <div class="f-cb"></div>
    </div>

</div>

<script src="http://lib.sinaapp.com/js/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
$('.content img').wrapAll(function(){
    return '<a href="'+$(this).attr('src')+'"  data-lightbox="roadtrip">'+$(this).html()+'</a>';
})

$('#gb_form').submit(function(event) {
    url = '{:U('guestbook/handleAdd')}';
    if($("input[name='name']").val() == ''){
        alert('姓名不能为空');
        $("input[name='name']").focus();
        return false;
    }
    if($("input[name='content']").val() == ''){
        alert('留言内容不能为空');
        $("input[name='content']").focus();
        return false;
    }

    $.post(url, $(this).serialize(), function(data, textStatus, xhr) {
        if(data == -1){
            alert('验证码错误');
            $('#code_img').click();
        }
        if(data == -2){
            alert('姓名不能为空');
            $("input[name='name']").focus();
        }
        if(data == -3){
            alert('留言内容不能为空');
            $("input[name='content']").focus();
        }
        if(data == 1){
            alert('提交留言成功，请等待管理员审核与回复！');
            window.location.reload();
        }
        if(data == -4){
            alert('抱歉，数据错误，添加留言失败');
        }
    });
    return false;
});
</script>

</body>
</html>
